<!DOCTYPE html>
<html  lang="zh-CN" >
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="theme-color" content="#fff" id="theme-color">
  <meta name="description" content="深山磨柴斧，一鸣震江湖">
  <link rel="icon" href="/img/ic_head.jpg">
  <title>Java过渡Kotlin02：数据类型</title>
  
  
  <meta property="og:title" content="Java过渡Kotlin02：数据类型">
  
  
  <meta property="og:url" content="http://example.com/2020/03/01/Java%E8%BF%87%E6%B8%A1Kotlin02%EF%BC%9A%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/index.html">
  
  
  <meta property="og:img" content="/img/ic_head.jpg">
  
  
  <meta property="og:img" content="深山磨柴斧，一鸣震江湖">
  
  
  <meta property="og:type" content="article">
  <meta property="og:article:published_time" content="2020-03-01">
  <meta property="og:article:modified_time" content="2021-04-14">
  <meta property="og:article:author" content="Cupster">
  
  
  <meta property="og:article:tag" content="Kotlin">
  
  
  
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
    var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
      }
    };
    setDarkmode();
  </script>
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
  </script>
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
  <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
  <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
  
  
  
  
<link rel="stylesheet" href="/css/main.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">

  
  
<link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">

  
  
<link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">

  
  
  
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <div class="wrapper">
    
    <nav class="navbar">
  <div class="navbar-logo">
    <span class="navbar-logo-main">
      
      <img class="navbar-logo-img" src="/img/ic_head.jpg" alt="logo">
      
      <span class="navbar-logo-dsc">不负明天</span>
    </span>
  </div>
  <div class="navbar-menu">
    
    <a href="/" class="navbar-menu-item">
    
    首页
    
    </a>
    
    <a href="/archives" class="navbar-menu-item">
    
    归档
    
    </a>
    
    <a href="/tags" class="navbar-menu-item">
    
    标签
    
    </a>
    
    <a href="/categories" class="navbar-menu-item">
    
    分类
    
    </a>
    
    <a href="/about" class="navbar-menu-item">
    
    关于
    
    </a>
    
    <a href="/links" class="navbar-menu-item">
    
    友链
    
    </a>
    
    <a class="navbar-menu-item darknavbar" id="dark"><i class="iconfont icon-weather"></i></a>
    <a class="navbar-menu-item searchnavbar" id="search"><i class="iconfont icon-search" style="font-size: 1.2rem; font-weight: 400;"></i></a>
  </div>
</nav>
    
    <div id="local-search" style="display: none;">
      <input class="navbar-menu-item" id="search-input" placeholder="请输入搜索内容...">
      <div id="search-content"></div>
    </div>
    
    <div class="section-wrap">
      <div class="container">
        <div class="columns">
          <main class="main-column">
<article class="card card-content">
  <header>
    <h1 class="post-title">
      Java过渡Kotlin02：数据类型
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2020-03-01T11:00:01.000Z">
      <i class="iconfont icon-calendar" style="margin-right: 2px;"></i>
      <span>2020-03-01</span>
    </time>
    
    <span class="dot"></span>
    
    <a href="/categories/Kotlin/" class="post-meta-link">Kotlin</a>
    
    
    
    <span class="dot"></span>
    <span>1.6k 字</span>
    
  </div>
  
  <div class="post-meta post-show-meta" style="margin-top: -10px;">
    <div style="display: flex; align-items: center;">
      <i class="iconfont icon-biaoqian" style="margin-right: 2px; font-size: 1.15rem;"></i>
      
      
        <a href="/tags/Kotlin/" class="post-meta-link">Kotlin</a>
      
    </div>
  </div>
  
  </header>
  <div id="section" class="post-content">
    <h1 id="一、基本数据类型"><a href="#一、基本数据类型" class="headerlink" title="一、基本数据类型"></a>一、基本数据类型</h1><pre><code>与Java基本一致
</code></pre>
<p>不同的是，字符不属于数值类型，是一个独立的数据类型</p>
<table>
<thead>
<tr>
<th>类型</th>
<th>位宽度</th>
</tr>
</thead>
<tbody><tr>
<td>Double</td>
<td>64</td>
</tr>
<tr>
<td>Float</td>
<td>32</td>
</tr>
<tr>
<td>Long</td>
<td>64</td>
</tr>
<tr>
<td>Int</td>
<td>32</td>
</tr>
<tr>
<td>Short</td>
<td>16</td>
</tr>
<tr>
<td>Byte</td>
<td>8</td>
</tr>
</tbody></table>
<h1 id="二、字面常量"><a href="#二、字面常量" class="headerlink" title="二、字面常量"></a>二、字面常量</h1><pre><code>未提及的均与Java一致
</code></pre>
<p> 长整形Long,以大写L结尾： 123456789L</p>
<p> Float使用F / f 结尾：123.50f  123.50F</p>
<p> 2进制以0b开头： 0b00001011</p>
<p><strong>不支持8进制</strong></p>
<p><strong>可以使用下划线增加数字的可读性</strong></p>
<pre><code>val oneMillion = 1_000_000
val creditCardNumber = 1234_5678_9012_3456L
val socialSecurityNumber = 999_99_9999L
val hexBytes = 0xFF_EC_DE_5E
val bytes = 0b11010010_01101001_10010100_10010010
</code></pre>
<h1 id="三、比较两个数字"><a href="#三、比较两个数字" class="headerlink" title="三、比较两个数字"></a>三、比较两个数字</h1><p>在 Kotlin 中，三个等号 === 表示比较对象地址，</p>
<p>两个 == 表示比较两个值大小。</p>
<pre><code>Kotlin 中没有基础数据类型，只有封装的数字类型，
每定义的一个变量，本质是封装了一个对象，这样可以保证不会出现空指针
</code></pre>
<p>案例：</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val a: Int = 10000
    println(a === a) // true，值相等，对象地址相等

    //经过了装箱，创建了两个不同的对象
    val boxedA: Int? = a
    val anotherBoxedA: Int? = a

    //虽然经过了装箱，但是值是相等的，都是10000
    println(boxedA === anotherBoxedA) //  false，值相等，对象地址不一样
    println(boxedA == anotherBoxedA) // true，值相等
&#125;
</code></pre>
<p><strong>注意1</strong></p>
<p>上面代码 a的值 在范围是 [-128, 127] 之间并不会创建新的对象，比较输出的都是 true，从 128 开始，比较的结果才为 false。</p>
<p><strong>注意2</strong></p>
<pre><code>val num: Int = 10000
val num1: Int = num
val num2: Int = num
println(num1 === num2)  //true
</code></pre>
<p>这里判断为地址相同不是因为有没有显示声明类型，而是类型都相同，都是数值类型，没有进行装箱操作。而案例中的类型是 Int? 可空类型，类型不同所以必须装箱，导致产生一个新对象。</p>
<p><strong>完整理解</strong></p>
<pre><code>// Int? Int? Int? 
val a1: Int? = 128 //超出Int范围，且可为空 ，理解为Java中的Object对象 ，
var boxedA: Int? = a1
var boxedB: Int? = a1
log(&quot; boxedA === boxedB ? &quot; + (boxedA === boxedB))//true  同类型 未装箱 地址相等
log(&quot; boxedA == boxedB ? &quot; + (boxedA == boxedB))//true

// Int Int? Int?
val a2: Int = 128   //超出Int范围，但确定为Int类型
boxedA = a2      //未显式声明类型，理解为Object
boxedB = a2
log(&quot; boxedA === boxedB ? &quot; + (boxedA === boxedB))//false  不同类型，封装，地址不同
//值相等
log(&quot; boxedA == boxedB ? &quot; + (boxedA == boxedB))//true

// Int? Int? Int?
val a3: Int? = 127  //Int类型的范围内，且明确赋值，不会二次封装变量，变量地址一致
boxedA = a3
boxedB = a3
log(&quot; boxedA === boxedB ? &quot; + (boxedA === boxedB))//true
//值相等
log(&quot; boxedA == boxedB ? &quot; + (boxedA == boxedB))//true

// Int Int? Int?
val a4: Int = 127  //Int类型的范围内，且明确赋值，不会二次封装变量，变量地址一致
boxedA = a4
boxedB = a4
log(&quot; boxedA === boxedB ? &quot; + (boxedA === boxedB))//true 
//值相等
log(&quot; boxedA == boxedB ? &quot; + (boxedA == boxedB))//true
</code></pre>
<p>​<br>​<br>    // Int Int Int<br>    val a5: Int = 128<br>    val boxedA2: Int = a5  //都是同类型，且数值相同，故地址一样<br>    val boxedB2: Int = a5</p>
<pre><code>log(&quot; boxedA === boxedB ? &quot; + (boxedA2 === boxedB2))//true
//值相等
log(&quot; boxedA == boxedB ? &quot; + (boxedA2 == boxedB2))//true
</code></pre>
<h1 id="四、类型转换"><a href="#四、类型转换" class="headerlink" title="四、类型转换"></a>四、类型转换</h1><pre><code>与Java不同
    与Java不同
        与Java不同
</code></pre>
<p>理解Kotlin中变量的定义，本质是封装了一个对象，对象并不能自动类型转换</p>
<pre><code>val b: Byte = 1 // OK, 字面值是静态检测的
val i: Int = b // 错误
</code></pre>
<p>应该为</p>
<pre><code>val i :Int = b.toInt()
</code></pre>
<p>每种数据都有以下转换方法</p>
<pre><code>toByte(): Byte
toShort(): Short
toInt(): Int
toLong(): Long
toFloat(): Float
toDouble(): Double
toChar(): Char
</code></pre>
<p>特殊情况：</p>
<p>有些情况下也是可以使用自动类型转化的，前提是可以根据上下文环境推断出正确的数据类型而且数学操作符会做相应的重载</p>
<pre><code>val l = 1L + 3 // Long + Int =&gt; Long
</code></pre>
<h1 id="五、位操作符"><a href="#五、位操作符" class="headerlink" title="五、位操作符"></a>五、位操作符</h1><p>对于Int Long类型，有：</p>
<pre><code>shl(bits) – 左移位 (Java’s &lt;&lt;)
shr(bits) – 右移位 (Java’s &gt;&gt;)
ushr(bits) – 无符号右移位 (Java’s &gt;&gt;&gt;)
and(bits) – 与
or(bits) – 或
xor(bits) – 异或
inv() – 反向
</code></pre>
<h1 id="六、字符"><a href="#六、字符" class="headerlink" title="六、字符"></a>六、字符</h1><pre><code>与Java不同
与Java不同
与Java不同
</code></pre>
<p>kotlin 中Char不能喝数字操作，且必须单引号包含起来 。</p>
<p>理解kotlin中变量声明自动封装成一个类的原理，便理解为什么不能和数字直接操作。</p>
<pre><code>fun decimalDigitValue(c: Char): Int &#123;
    if (c !in &#39;0&#39;..&#39;9&#39;)
        throw IllegalArgumentException(&quot;Out of range&quot;)
    return c.toInt() - &#39;0&#39;.toInt() // 显式转换为数字
&#125;   
</code></pre>
<h1 id="七、布尔"><a href="#七、布尔" class="headerlink" title="七、布尔"></a>七、布尔</h1><pre><code>与Java一致
</code></pre>
<h1 id="八、数组"><a href="#八、数组" class="headerlink" title="八、数组"></a>八、数组</h1><p>数组用类 Array 实现，并且还有一个 size 属性及 get 和 set 方法，由于使用 [] 重载了 get 和 set 方法，所以我们可以通过下标很方便的获取或者设置数组对应位置的值。</p>
<p>数组的创建两种方式：一种是使用函数arrayOf()；另外一种是使用工厂函数</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    //[1,2,3]
    val a = arrayOf(1, 2, 3)
    //[0,2,4]
    val b = Array(3, &#123; i -&gt; (i * 2) &#125;)

    //读取数组内容
    println(a[0])    // 输出结果：1
    println(b[1])    // 输出结果：2
&#125;
</code></pre>
<p><strong>Kotlin 中数组是不协变的</strong></p>
<p>除了类Array，还有ByteArray, ShortArray, IntArray，用来表示各个类型的数组，省去了装箱操作，因此效率更高，其用法同Array一样</p>
<p>val x: IntArray = intArrayOf(1, 2, 3)<br>x[0] = x[1] + x[2]</p>
<h1 id="九、字符串"><a href="#九、字符串" class="headerlink" title="九、字符串"></a>九、字符串</h1><p>和 Java 一样，String 是不可变的。</p>
<p>方括号 [] 语法可以很方便的获取字符串中的某个字符，也可以通过 for 循环来遍历：</p>
<pre><code>for (c in str) &#123;
    println(c)
&#125;
</code></pre>
<p>Kotlin 支持三个引号 “”” 扩起来的字符串，支持多行字符串，比如：</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val text = &quot;&quot;&quot;
    多行字符串
    多行字符串
    &quot;&quot;&quot;
    println(text)   // 输出有一些前置空格
&#125;
</code></pre>
<p>String 可以通过 trimMargin() 方法来删除多余的空白。</p>
<p>默认 | 用作边界前缀，但你可以选择其他字符并作为参数传入，比如 trimMargin(“&gt;”)</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val text = &quot;&quot;&quot;
    |多行字符串
    |菜鸟教程
    |多行字符串
    |Runoob
    &quot;&quot;&quot;.trimMargin()
    println(text)    // 前置空格删除了
&#125;
</code></pre>
<p><strong>字符串模板</strong></p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val i = 10
    val s = &quot;i = $i&quot; // 求值结果为 &quot;i = 10&quot;
    println(s)
&#125;
</code></pre>
<p>或者用花括号扩起来的任意表达式</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val s = &quot;runoob&quot;
    val str = &quot;$s.length is $&#123;s.length&#125;&quot; // 求值结果为 &quot;runoob.length is 6&quot;
    println(str)
&#125;
</code></pre>
<p>原生字符串和转义字符串内部都支持模板。 如果你需要在原生字符串中表示字面值 $ 字符（它不支持反斜杠转义）</p>
<pre><code>fun main(args: Array&lt;String&gt;) &#123;
    val price = &quot;&quot;&quot;
    $&#123;&#39;$&#39;&#125;9.99
    &quot;&quot;&quot;
    println(price)  // 求值结果为 $9.99
&#125;
</code></pre>

  </div>
  <div>
  
  <div class="post-note note-warning copyright" style="margin-top: 42px">
    <p><span style="font-weight: bold;">作者：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/about">Cupster</a></p>
    <p><span style="font-weight: bold;">文章链接：</span><a target="_blank" rel="nofollow noopener noreferrer" href="http://example.com/2020/03/01/Java%E8%BF%87%E6%B8%A1Kotlin02%EF%BC%9A%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/">http://example.com/2020/03/01/Java%E8%BF%87%E6%B8%A1Kotlin02%EF%BC%9A%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B/</a></p>
    <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
  </div>
  
  </div>
</article>
<div class="nav">
  
  <div class="nav-item-prev">
    <a href="/2020/03/01/Java过渡Kotlin03：流程控制/" class="nav-link">
      <i class="iconfont icon-left nav-prev-icon"></i>
      <div>
        <div class="nav-label">上一篇</div>
        
        <div class="nav-title">Java过渡Kotlin03：流程控制 </div>
        
      </div>
    </a>
  </div>
  
  
  <div class="nav-item-next">
    <a href="/2020/03/01/Java过渡Kotlin01：基础语法/" class="nav-link">
      <div>
        <div class="nav-label">下一篇</div>
        
        <div class="nav-title">Java过渡Kotlin01：基础语法 </div>
        
      </div>
      <i class="iconfont icon-right nav-next-icon"></i>
    </a>
  </div>
  
</div>

<div class="card card-content toc-card" id="mobiletoc">
  <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">一、基本数据类型</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%AD%97%E9%9D%A2%E5%B8%B8%E9%87%8F"><span class="toc-text">二、字面常量</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%AF%94%E8%BE%83%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97"><span class="toc-text">三、比较两个数字</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">四、类型转换</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E4%BD%8D%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-text">五、位操作符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AD%E3%80%81%E5%AD%97%E7%AC%A6"><span class="toc-text">六、字符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%83%E3%80%81%E5%B8%83%E5%B0%94"><span class="toc-text">七、布尔</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AB%E3%80%81%E6%95%B0%E7%BB%84"><span class="toc-text">八、数组</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B9%9D%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-text">九、字符串</span></a></li></ol>
</div></main>
          <aside class="left-column">
            
            <div class="card card-author">
              
<img src="/img/ic_head.jpg" class="author-img">

<p class="author-name">Cupster</p>
<p class="author-description">深山磨柴斧，一鸣震江湖</p>
<div class="author-message">
  <a class="author-posts-count" href="/archives">
    <span>66</span>
    <span>文章</span>
  </a>
  <a class="author-categories-count" href="/categories">
    <span>5</span>
    <span>分类</span>
  </a>
  <a class="author-tags-count" href="/tags">
    <span>31</span>
    <span>标签</span>
  </a>
</div>

<div class="author-card-society">
  
    <div class="author-card-society-icon">
      <a target="_blank" rel="noopener" href="https://cupster.blog.csdn.net/">
        <i class="iconfont /img/ic_csdn.png society-icon"></i>
      </a>
    </div>
  
</div>

            </div>
            
            <div class="sticky-tablet">
  
  
  <article class="display-when-two-columns spacer">
    <div class="card card-content toc-card">
      <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">一、基本数据类型</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%AD%97%E9%9D%A2%E5%B8%B8%E9%87%8F"><span class="toc-text">二、字面常量</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%AF%94%E8%BE%83%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97"><span class="toc-text">三、比较两个数字</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">四、类型转换</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E4%BD%8D%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-text">五、位操作符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AD%E3%80%81%E5%AD%97%E7%AC%A6"><span class="toc-text">六、字符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%83%E3%80%81%E5%B8%83%E5%B0%94"><span class="toc-text">七、布尔</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AB%E3%80%81%E6%95%B0%E7%BB%84"><span class="toc-text">八、数组</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B9%9D%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-text">九、字符串</span></a></li></ol>
    </div>
  </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header"><i class="iconfont icon-fenlei" style="padding-right: 2px;"></i>分类</div>
  <div class="categories-list">
    
      <a href="/categories/Android/">
        <div class="categories-list-item">
          Android
          <span class="categories-list-item-badge">38</span>
        </div>
      </a>
    
      <a href="/categories/Linux/">
        <div class="categories-list-item">
          Linux
          <span class="categories-list-item-badge">6</span>
        </div>
      </a>
    
      <a href="/categories/Dev-Base/">
        <div class="categories-list-item">
          Dev-Base
          <span class="categories-list-item-badge">12</span>
        </div>
      </a>
    
      <a href="/categories/Kotlin/">
        <div class="categories-list-item">
          Kotlin
          <span class="categories-list-item-badge">9</span>
        </div>
      </a>
    
      <a href="/categories/自动化脚本/">
        <div class="categories-list-item">
          自动化脚本
          <span class="categories-list-item-badge">1</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header"><i class="iconfont icon-biaoqian" style="padding-right: 2px;"></i>热门标签</div>
  <div class="tags-list">
    
    <a href="/tags/Android/" title="Android"><div class="tags-list-item">Android</div></a>
    
    <a href="/tags/Android自定义View/" title="Android自定义View"><div class="tags-list-item">Android自定义View</div></a>
    
    <a href="/tags/MacOS/" title="MacOS"><div class="tags-list-item">MacOS</div></a>
    
    <a href="/tags/Kotlin/" title="Kotlin"><div class="tags-list-item">Kotlin</div></a>
    
    <a href="/tags/Android持久化/" title="Android持久化"><div class="tags-list-item">Android持久化</div></a>
    
    <a href="/tags/CentOS/" title="CentOS"><div class="tags-list-item">CentOS</div></a>
    
    <a href="/tags/Linux/" title="Linux"><div class="tags-list-item">Linux</div></a>
    
    <a href="/tags/Android事件/" title="Android事件"><div class="tags-list-item">Android事件</div></a>
    
    <a href="/tags/Android基础/" title="Android基础"><div class="tags-list-item">Android基础</div></a>
    
    <a href="/tags/Android手势/" title="Android手势"><div class="tags-list-item">Android手势</div></a>
    
    <a href="/tags/Scrcpy/" title="Scrcpy"><div class="tags-list-item">Scrcpy</div></a>
    
    <a href="/tags/Android动画/" title="Android动画"><div class="tags-list-item">Android动画</div></a>
    
    <a href="/tags/Git/" title="Git"><div class="tags-list-item">Git</div></a>
    
    <a href="/tags/Java/" title="Java"><div class="tags-list-item">Java</div></a>
    
    <a href="/tags/Docker/" title="Docker"><div class="tags-list-item">Docker</div></a>
    
    <a href="/tags/Android-Dialog/" title="Android Dialog"><div class="tags-list-item">Android Dialog</div></a>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
          <aside class="right-column">
            <div class="sticky-widescreen">
  
  
  <article class="card card-content toc-card">
    <div class="toc-header"><i class="iconfont icon-menu" style="padding-right: 2px;"></i>目录</div>
<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">一、基本数据类型</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%AD%97%E9%9D%A2%E5%B8%B8%E9%87%8F"><span class="toc-text">二、字面常量</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%AF%94%E8%BE%83%E4%B8%A4%E4%B8%AA%E6%95%B0%E5%AD%97"><span class="toc-text">三、比较两个数字</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">四、类型转换</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%94%E3%80%81%E4%BD%8D%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-text">五、位操作符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AD%E3%80%81%E5%AD%97%E7%AC%A6"><span class="toc-text">六、字符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%83%E3%80%81%E5%B8%83%E5%B0%94"><span class="toc-text">七、布尔</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%85%AB%E3%80%81%E6%95%B0%E7%BB%84"><span class="toc-text">八、数组</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B9%9D%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-text">九、字符串</span></a></li></ol>
  </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header"><i class="iconfont icon-wenzhang_huaban" style="padding-right: 2px;"></i>最近文章</div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-03-02</div>
        <a href="/2021/03/02/Git commit规范/"><div class="recent-posts-item-content">Git commit规范</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-02-16</div>
        <a href="/2021/02/16/AutoJS一文精通AutoJS脚本教程详解/"><div class="recent-posts-item-content">AutoJS一文精通AutoJS脚本教程详解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-21</div>
        <a href="/2021/01/21/架构师进阶：注解Annotation全解/"><div class="recent-posts-item-content">架构师进阶：注解Annotation全解</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2021-01-06</div>
        <a href="/2021/01/06/ConstraintLayout详解/"><div class="recent-posts-item-content">ConstraintLayout详解</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
          </aside>
        </div>
      </div>
    </div>
  </div>
  
  <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>Copyright ©
          
          2020 -
          
          2021
        </span>
        &nbsp;
        <a href="/" class="footer-link">不负明天 </a>
      </div>
    </div>

    
    <div class="footer-dsc">
      
      Powered by
      <a href="https://hexo.io/" class="footer-link" target="_blank" rel="nofollow noopener noreferrer">&nbsp;Hexo </a>
      
      
      <span>&nbsp;|&nbsp;</span>
      
      
      Theme -
      <a href="https://github.com/theme-kaze" class="footer-link" target="_blank"
        rel="nofollow noopener noreferrer">&nbsp;Kaze</a>
      
    </div>
    
    
    
    
      <div class="footer-dsc">
        
        本站总访问量686<span id="busuanzi_value_site_pv"></span>次
        
        
        <span>&nbsp;|&nbsp;</span>
        
        
        本站总访客数219<span id="busuanzi_value_site_uv"></span>次
        
      </div>
      
    
</footer>
  <a role="button" id="scrollbutton" class="basebutton"  aria-label="回到顶部">
  <i class="iconfont icon-arrowleft button-icon"></i>
</a>
<a role="button" id="menubutton" class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a role="button" id="popbutton" class="basebutton" aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a role="button" id="darkbutton" class="basebutton darkwidget" aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a role="button" id="searchbutton" class="basebutton searchwidget" aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a>

  
  
  
  <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img');
    var i;
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a');
      wrapper.setAttribute('href', img[i].getAttribute('data-src'));
      wrapper.setAttribute('aria-label', 'illustration');
      wrapper.style.cssText = 'width: 100%; display: flex; justify-content: center;';
      if (img[i].alt) wrapper.dataset.caption = img[i].alt;
      wrapper.dataset.nolink = true;
      img[i].before(wrapper);
      wrapper.append(img[i]);
      var divWrap = document.createElement('div');
      divWrap.classList.add('gallery');
      wrapper.before(divWrap);
      divWrap.append(wrapper);
    }
    baguetteBox.run('.gallery');
  }
</script>
<script>loadScript("/js/lib/lightbox/baguetteBox.min.js", addImgLayout)</script>
  
  
  
<script src="/js/main.js"></script>

  
  <script>loadScript("/js/lib/busuanzi.min.js")</script>
  
  
  <script>
    var addLazyload = function () {
      var observer = lozad('.lozad', {
        load: function (el) {
          el.srcset = el.getAttribute('data-src');
        },
        loaded: function (el) {
          el.classList.add('loaded');
        }
      });
      observer.observe();
    }
  </script>
  <script>loadScript("/js/lib/lozad.min.js", addLazyload)</script>
  
  
</body>

</html>